-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/get points cities #48
Conversation
.env.example
Outdated
@@ -1,14 +0,0 @@ | |||
TZ=UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por que removeu esta arquivo, jovem? Ele existe para servir de exemplo para criação do arquivo .env
e não tem valores reais, são somente exemplos.
package-lock.json
Outdated
@@ -0,0 +1,11698 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este arquivo não deveria ser enviado, o projeto já utiliza Yarn como gerenciador de dependências. Utilizar duas ferramentas pode trazer inconsistências para o projeto.
package.json
Outdated
@@ -53,7 +53,7 @@ | |||
"date-fns": "^2.30.0", | |||
"dotenv": "16.3.1", | |||
"ejs": "^2.6.1", | |||
"express": "4.18.2", | |||
"express": "^4.19.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por favor, manter a versão sem o ^
, para manter a versão exata. Você pode fazer isso adicionando -E
no momento da instação, ou simplesmente removendo o caracter aqui no arquivo e executando o comando `install´ de novo.
|
||
export const ListaTodosOsTombosComLocalizacao = async (req, res, next) => { | ||
try { | ||
const { cidade, page, search, limit } = req.query; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O projeto já tem um middleware que faz o tratamento e cálculo dos parâmetros para paginação, vê como está sendo feito em outras rotas e segue o mesmo padrão, por favor, o nome do arquivo é listagens-middleware.js
.
hcf: tombo.hcf, | ||
latitude: tombo.latitude, | ||
longitude: tombo.longitude, | ||
cidade: cidadeObj ? cidadeObj.nome : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ao invés de devolver somente o nome da cidade da chave cidade
, cria a chave como um objeto e coloca os dados da cidade dentro.
Exemplo:
return {
hcf: tombo.hcf,
latitude: tombo.latitude,
longitude: tombo.longitude,
cidade: {
nome: cidadeObj ? cidadeObj.nome : null,
latitude: cidadeObj ? cidadeObj.latitude : null,
longitude: cidadeObj ? cidadeObj.longitude : null,
}
};
const limitInt = parseInt(limit, 10) || 5; | ||
const offset = (pageInt - 1) * limitInt; | ||
|
||
const queryOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acho que conseguimos melhorar esta lógica aqui para não repetir tanto o código. Você pode ir adicionando os novos parâmetros na query caso eles existam ou não. Você pode verificar na listagem de tombos como isso é feito. Se ficar com alguma dúvida me avisa e conversamos por chamada.
src/routes/cidades.js
Outdated
.get([ | ||
controller.listagem, | ||
]); | ||
app.route('/pontos').get([controller.ListaTodosOsTombosComLocalizacao]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Como é uma listagem de tombos, melhor mover esta rota e arquivos para o diretório "tombos" ao invés de "cidades".
|
Descrição:
-src/controllers/cidade-controller.js:
adicionei a funcao ListaTodosOsTombosComLocalizacao:|
retorna um findAll de todos os pontos desta maneira:
GET /api/pontos/
{"hcf":22372,"latitude":-24.12138888888889,"longitude":-49.62388888888889,"cidade":"Sengés","latitudeCidade":-24.1129,"longitudeCidade":-49.4616}
{"hcf":1,"latitude":null,"longitude":null,"cidade":"Campo Mourão","latitudeCidade":-24.0463,"longitudeCidade":-52.378}
{hcf, latitude, longitude, cidade, latitudeCidade, longitudeCidade}
Tambem tem os filtros para tratar o pin da cidade:
search: hcf;
cidade: CidadeBuscada;
page: paginacao;
limit: Esta setado 5.
exemplo:
http://localhost:3000/api/pontos/?search=216&cidade=Araruna&page=1&limit=5
Resposta:
{
"points": [
{
"hcf": 216,
"latitude": null,
"longitude": null,
"cidade": "Araruna",
"latitudeCidade": -23.9315,
"longitudeCidade": -52.5021
}
],
"totalPoints": 1,
"totalPages": 1,
"currentPage": 1
}
caso nao ache o ponto especifico digitado, ele retorna um numero parecido ao digitado, se tiver somente, Exemplo:
hcf:104
http://localhost:3000/api/pontos/?search=104&cidade=Araruna&page=1&limit=5
Resposta:
{
"points": [
{
"hcf": 104,
"latitude": null,
"longitude": null,
"cidade": "Araruna",
"latitudeCidade": -23.9315,
"longitudeCidade": -52.5021
},
{
"hcf": 4104,
"latitude": null,
"longitude": null,
"cidade": "Araruna",
"latitudeCidade": -23.9315,
"longitudeCidade": -52.5021
}
],
"totalPoints": 2,
"totalPages": 1,
"currentPage": 1
}
Achou o hcf 104 que existe e tambem retornou o hcf 4104 que e parecido, caso ha erro de digitacao do usuario, por exemplo.
-src/routes/cidades.js:
somente adicionei a funcao criada:
app.route('/pontos').get([controller.ListaTodosOsTombosComLocalizacao]);
: )